<?php

session_start();
if(!array_key_exists("user", $_SESSION) || $_SESSION['account'] != 1){
	header("Location: ../common/redirect.php");
	exit;
}

include_once("../class/db.php");
$db = new db();

$sql = "SELECT course.name, course.schedule_day, course.schedule_hour FROM users, course WHERE users.school_level = course.school_level and users.grade = course.grade and username = {$_SESSION['user']}";
$user_school_data = $db->execute($sql, "all");

$sql = "SELECT course.id, course.name, course.start_date, course.end_date FROM mycourses, course WHERE course.id = mycourses.course_id AND mycourses.username = {$_SESSION['user']}";
$user_course_data = $db->execute($sql, "all");

$sql = "SELECT id, name, creator, category, price FROM course WHERE price > 0 ORDER BY creation_date DESC LIMIT 10";
$available_course_data = $db->execute($sql, "all");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PIE EDUCATION | My Classes</title>
<link rel="stylesheet" type="text/css" href="/css/style-student.css" />
<link href="/css/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="/js/index.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script language="Javascript1.2">
<!--
setTimeout('location.href="/logout.php?expire=1"',600000);
// -->
</script>
<script>
	$(document).ready(function() {
		$("#accordion").accordion({ autoHeight: false });
	});
</script>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-35230372-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</head>

<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td bgcolor="#000000"><table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="350" height="30">&nbsp;</td>
        <td align="right" valign="bottom"><a href="class.php" class="top-menu" style="color:#999">MY COURSES</a> <a href="schedule.php" class="top-menu" style="color:#999">CALENDAR</a> <a href="homework.php" class="top-menu" style="color:#999">HOMEWORK</a> <a href="test.php" class="top-menu" style="color:#999">EXAMS</a>  <a href="history.php" class="top-menu" style="color:#999">RECORDS</a> <a href="tools.php" class="top-menu" style="color:#999">TOOLS</a> <a href="/logout.php" class="top-menu" style="color:#999">SIGN OUT</a></td>
      </tr>
	  <tr>
        <td>&nbsp;</td>
        <td align="right" valign="bottom"><a href="/profile/" class="login-menu" style="color:#FFF"><?php echo $_SESSION['name'].' '.$_SESSION['lname']; ?></a> <a href="/common/settings.php" class="login-menu" style="color:#FFF">Change Settings</a> <a href="/common/redirect.php" class="login-menu" style="color:#FFF">My Documents</a> <a href="/network/" class="login-menu" style="color:#FFF">My Network</a></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="30" style="background-image:url(/images/top-bg-student.png); background-repeat:repeat-x">&nbsp;</td>
  </tr>
  <tr>
    <td height="700" valign="top"><table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td>
          <div id="accordion">
            <h3><a href="#">My Classes</a></h3>
            <div>
              <?php
              if($user_school_data == false){
			  echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td height="100" align="center" style="font-family:Arial, Helvetica, sans-serif; font-size:14px; color:#00F"><strong>You are not enrolled into any school yet, but you can always see your active courses below</strong></td>
                </tr>
              </table>';
			  } else {
              echo '<table width="100%" border="0" cellspacing="4" cellpadding="4">
                <tr>
                  <td align="left" width="16%" style="font-size:14px; font-family:Arial, Helvetica, sans-serif;border-bottom-color:#CCC; border-bottom:thin; border-bottom-style:dashed; padding-bottom:10px"><strong>Class Name</strong></td>
                  <td align="center" width="12%" style="font-size:14px; font-family:Arial, Helvetica, sans-serif;border-bottom-color:#CCC; border-bottom:thin; border-bottom-style:dashed; padding-bottom:10px"><strong>Monday</strong></td>
                  <td align="center" width="12%" style="font-size:14px; font-family:Arial, Helvetica, sans-serif;border-bottom-color:#CCC; border-bottom:thin; border-bottom-style:dashed; padding-bottom:10px"><strong>Tuesday</strong></td>
                  <td align="center" width="12%" style="font-size:14px; font-family:Arial, Helvetica, sans-serif;border-bottom-color:#CCC; border-bottom:thin; border-bottom-style:dashed; padding-bottom:10px"><strong>Wednesday</strong></td>
                  <td align="center" width="12%" style="font-size:14px; font-family:Arial, Helvetica, sans-serif;border-bottom-color:#CCC; border-bottom:thin; border-bottom-style:dashed; padding-bottom:10px"><strong>Thursday</strong></td>
                  <td align="center" width="12%" style="font-size:14px; font-family:Arial, Helvetica, sans-serif;border-bottom-color:#CCC; border-bottom:thin; border-bottom-style:dashed; padding-bottom:10px"><strong>Friday</strong></td>
                  <td align="center" width="12%" style="font-size:14px; font-family:Arial, Helvetica, sans-serif;border-bottom-color:#CCC; border-bottom:thin; border-bottom-style:dashed; padding-bottom:10px"><strong>Saturday</strong></td>
                  <td width="12%" align="center" style="font-size:14px; font-family:Arial, Helvetica, sans-serif;border-bottom-color:#CCC; border-bottom:thin; border-bottom-style:dashed; padding-bottom:10px"><strong>Sunday</strong></td>
                </tr>';
				foreach($user_school_data as $school_grades){
					$school_days = explode(",", $school_grades['schedule_day']);
					$school_hour = explode(",", $school_grades['schedule_hour']);
					echo '<tr>
					  <td style="font-family:Arial, Helvetica, sans-serif; font-size:12px"><strong>'.$school_grades['name'].'</strong></td>
					  <td style="font-family:Arial, Helvetica, sans-serif; font-size:12px" align="center">';
					  $counter = 0;
					  foreach($school_days as $set_day){
						  $days = explode("-", $set_day);
						  foreach($days as $day){
							  if($day == "mo" ){
							  	echo $school_hour[$counter];
						  	  }
						  }
						  $counter++;
					  }
					  echo '</td>
					  <td style="font-family:Arial, Helvetica, sans-serif; font-size:12px" align="center">';
					  $counter = 0;
					  foreach($school_days as $set_day){
						  $days = explode("-", $set_day);
						  foreach($days as $day){
							  if($day == "tu" ){
							  	echo $school_hour[$counter];
						  	  }
						  }
						  $counter++;
					  }
					  echo '</td>
					  <td style="font-family:Arial, Helvetica, sans-serif; font-size:12px" align="center">';
					  $counter = 0;
					  foreach($school_days as $set_day){
						  $days = explode("-", $set_day);
						  foreach($days as $day){
							  if($day == "we" ){
							  	echo $school_hour[$counter];
						  	  }
						  }
						  $counter++;
					  }
					  echo '</td>
					  <td style="font-family:Arial, Helvetica, sans-serif; font-size:12px" align="center">';
					  $counter = 0;
					  foreach($school_days as $set_day){
						  $days = explode("-", $set_day);
						  foreach($days as $day){
							  if($day == "th" ){
							  	echo $school_hour[$counter];
						  	  }
						  }
						  $counter++;
					  }
					  echo '</td>
					  <td style="font-family:Arial, Helvetica, sans-serif; font-size:12px" align="center">';
					  $counter = 0;
					  foreach($school_days as $set_day){
						  $days = explode("-", $set_day);
						  foreach($days as $day){
							  if($day == "fr" ){
							  	echo $school_hour[$counter];
						  	  }
						  }
						  $counter++;
					  }
					  echo '</td>
					  <td style="font-family:Arial, Helvetica, sans-serif; font-size:12px" align="center">';
					  $counter = 0;
					  foreach($school_days as $set_day){
						  $days = explode("-", $set_day);
						  foreach($days as $day){
							  if($day == "sa" ){
							  	echo $school_hour[$counter];
						  	  }
						  }
						  $counter++;
					  }
					  echo '</td>
					  <td style="font-family:Arial, Helvetica, sans-serif; font-size:12px" align="center">';
					  $counter = 0;
					  foreach($school_days as $set_day){
						  $days = explode("-", $set_day);
						  foreach($days as $day){
							  if($day == "su" ){
							  	echo $school_hour[$counter];
						  	  }
						  }
						  $counter++;
					  }
					  echo '</td>
					</tr>';
				}
              echo '</table>';
			  }
			  ?>
            </div>
            <h3><a href="#">My Courses</a></h3>
            <div>
              <?php
              if($user_course_data == false){
			  echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td height="100" align="center" style="font-family:Arial, Helvetica, sans-serif; font-size:14px; color: #666"><p><strong>You are not enrolled into any course yet. Click on the button below to see all the course and pick one</strong></p>
                    <p><a href="#" class="button blue" style="color:#FFF">I Want a Course</a></p></td>
                  </tr>
                </table>';
			  } else {
                echo '<table width="100%" border="0" cellspacing="4" cellpadding="4">
                  <tr>
                    <td width="55%" style="font-size:14px; font-family:Arial, Helvetica, sans-serif;border-bottom-color:#CCC; border-bottom:thin; border-bottom-style:dashed; padding-bottom:10px"><strong>Course Name</strong></td>
                    <td align="center" width="15%" style="font-size:14px; font-family:Arial, Helvetica, sans-serif;border-bottom-color:#CCC; border-bottom:thin; border-bottom-style:dashed; padding-bottom:10px"><strong>Start Date</strong></td>
                    <td align="center" width="15%" style="font-size:14px; font-family:Arial, Helvetica, sans-serif;border-bottom-color:#CCC; border-bottom:thin; border-bottom-style:dashed; padding-bottom:10px"><strong>End Date</strong></td>
                    <td align="center" width="15%" style="font-size:14px; font-family:Arial, Helvetica, sans-serif;border-bottom-color:#CCC; border-bottom:thin; border-bottom-style:dashed; padding-bottom:10px"><strong>Description</strong></td>
                  </tr>';
				  foreach($user_course_data as $course){
                  echo '<tr>
                    <td style="font-family:Arial, Helvetica, sans-serif; font-size:12px">'.$course['name'].'</td>
                    <td align="center" style="font-family:Arial, Helvetica, sans-serif; font-size:12px">'.$course['start_date'].'</td>
                    <td align="center" style="font-family:Arial, Helvetica, sans-serif; font-size:12px">'.$course['end_date'].'</td>
                    <td align="center" style="font-family:Arial, Helvetica, sans-serif; font-size:12px"><a href="#" onclick="javascript:openDescription('.$course['id'].')">View Description</a></td>
                  </tr>';
				  }
                echo '</table>';
			  }
				?>
            </div>
            <h3><a href="#">What's New</a></h3>
            <div>
                  <table width="100%" border="0" cellspacing="4" cellpadding="4">
                    <tr>
                      <td width="60%" style="font-size:14px; font-family:Arial, Helvetica, sans-serif;border-bottom-color:#CCC; border-bottom:thin; border-bottom-style:dashed; padding-bottom:10px"><strong>Course Name</strong></td>
                      <td align="center" width="10%" style="font-size:14px; font-family:Arial, Helvetica, sans-serif;border-bottom-color:#CCC; border-bottom:thin; border-bottom-style:dashed; padding-bottom:10px"><strong>Price</strong></td>
                      <td align="center" width="15%" style="font-size:14px; font-family:Arial, Helvetica, sans-serif;border-bottom-color:#CCC; border-bottom:thin; border-bottom-style:dashed; padding-bottom:10px"><strong>Created By</strong></td>
                      <td align="center" width="15%" style="font-size:14px; font-family:Arial, Helvetica, sans-serif;border-bottom-color:#CCC; border-bottom:thin; border-bottom-style:dashed; padding-bottom:10px"><strong>Category</strong></td>
                    </tr>
                    <?php
					foreach($available_course_data as $available_courses){
                    echo '<tr>
                      <td style="font-family:Arial, Helvetica, sans-serif; font-size:12px">'.$available_courses['name'].'</td>
                      <td align="center" style="font-family:Arial, Helvetica, sans-serif; font-size:12px"><a href="#'.$available_courses['id'].'">'.$available_courses['price'].'</a></td>
                      <td align="center" style="font-family:Arial, Helvetica, sans-serif; font-size:12px">'.$available_courses['creator'].'</td>
                      <td align="center" style="font-family:Arial, Helvetica, sans-serif; font-size:12px">'.$available_courses['category'].'</td>
                    </tr>';
					}
                    ?>
                  </table>
            </div>
        </div>
          </td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td height="30" style=" background-image:url(../images/bottom-bg-student.png); background-repeat:repeat-x;">&nbsp;</td>
  </tr>
  <tr>
    <td height="50" align="center" bgcolor="#000000" style="color:#fff; font-family:Arial, Helvetica, sans-serif">PIE.EDU All Rights Reserved 2012<br />
      <a href="/common/privacy.php" class="bottom-menu" style="color:#999">Privacy Policy</a> | <a href="/common/terms.php" class="bottom-menu"  style="color:#999">Terms of Use</a> | <a href="/help/main.php" class="bottom-menu" style="color:#999">Help Center</a> | <a href="/common/jobs.php" class="bottom-menu" style="color:#999">Jobs</a></td>
  </tr>
</table>
</body>
</html>